package com.xbdun.service.bmp.facade;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xbdun.common.api.Client;
import com.xbdun.common.util.CommonUtil;
import com.xbdun.facade.bmp.response.system.PlatformMenuResponse;
import com.xbdun.facade.bmp.result.system.LoginOrgUserMenuResult;
import com.xbdun.facade.bmp.service.system.OpenAuthFacade;
import com.xbdun.service.bmp.service.system.OrgUserService;
import com.xbdun.service.bmp.service.system.PlatfromService;

import lombok.extern.slf4j.Slf4j;
@Component
@Slf4j
public class OpenAuthFacadeImpl implements OpenAuthFacade {
	@Autowired
	OrgUserService orgUserService;
	@Autowired
	PlatfromService platfromService;
	public LoginOrgUserMenuResult loginOrgUserMenu(Client client) {
		LoginOrgUserMenuResult result = new LoginOrgUserMenuResult();
		
		try {
			CommonUtil.validateClient(client);
			log.info("start - 用户登录成功后查询菜单,{}",client);
			
			result.setData(orgUserService.loginOrgUserMenu(client));
		} catch (Exception ex) {
			result.setBizException(ex);
			log.error("用户登录成功后查询菜单 失败,入参:{},异常:{}", client, ex);
		} finally {
			log.info("end -用户登录成功后查询菜单 结果:{}", result);
		}
		return result;
	}
	
	public String getUserAuthEvent(Client client) {
		String authEvent = null;
		try {
			CommonUtil.validateClient(client);
			log.info("start - 用户登录成功后查询权限,{}",client);
			authEvent = orgUserService.getUserAuthEvent(client);
		} catch (Exception ex) {
			log.error("登录成功后，获取当前系统权限,入参:{},异常:{}", client, ex);
		} finally {
			log.info("end -用户登录成功后查询权限 结果:{}", authEvent);
		}
		return authEvent;
	}

	public List<PlatformMenuResponse> getPlatformMenu(int platCode) {
		List<PlatformMenuResponse> result = null;
		try{
			result = platfromService.getPlatformMenu(platCode);	
		}catch(Exception e){
			log.error("根据平台编号获取到该平台菜单异常",e);
		}
		return result;
		
	}

	public String getSysPlatAuth(String menuKey) {
		try{
			return platfromService.getSysPlatAuth(menuKey);	
		}catch(Exception e){
			log.error("根据平台编号获取到该平台菜单异常",e);
		}
		return null;
	}

	public String getCurrentOrgAuth(long orgCode, int platCode) {
		try{
			return platfromService.getCurrentOrgAuth(orgCode,platCode);	
		}catch(Exception e){
			log.error("根据平台编号获取到该平台菜单异常",e);
		}
		return null;
	}
}
